	//注册表单的非空校验
	function checkForm() {
		var username = document.getElementById("username").value;
	
		if (username == null || username == "") {
			alert("用户名不能为空");
			return false;
		}
	
		var password = document.getElementById("password").value;
		if (password == null || password == "") {
			alert("密码不能为空");
			return false;
		}
	
		var repassword = document.getElementById("repassword").value;
		if (repassword == null || repassword == "") {
			alert("确认密码不能为空");
			return false;
		}
		if (repassword != password) {
			alert("两次密码输入不一致");
			return false;
		}
	
		var email = document.getElementById("email").value;
		if (email == null || email == "") {
			alert("邮箱不能为空");
			return false;
		}
		var phone = document.getElementById("phone").value;
		if (phone == null || phone == "") {
			alert("电话不能为空");
			return false;
		}
		var validatecode = document.getElementById("validatecode").value;
		if (validatecode == null || validatecode == "") {
			alert("验证码不能为空");
			return false;
		}
	}



	
	// ajax校验用户名是否存在


    function  creatXMLHttpRequest() {
        var xmlhttp;
        try {
            xmlhttp=new XMLHttpRequest();//?????
        }
        catch(e) {
            try{
                xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
            }
            catch (e)
            {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
            }
        }
        return xmlhttp;
    }
    function checkUsername() {
        var reg = /^[a-zA-Z]\w{2,10}$/;
        var username = document.getElementById("username").value;// 获取用户名
        var msg=document.getElementById("msg");

        var f = reg.test(username);
        // alert(f);
        if (f == false) {
            msg.innerText = "用户名格式不对";
            msg.style.color = "red";
            return;
        }


        var xmlHTTP=creatXMLHttpRequest();
        var username=document.getElementById("username").value;


        xmlHTTP.open("GET","/shop/userRegist?username="+username,true);
        xmlHTTP.send(null);//GET方法
//            xmlHTTP.open("POST","/guo/userServlet",true);
//            xmlHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//            xmlHTTP.send("username="+username);//POST方法

        xmlHTTP.onreadystatechange = function() {

            if(xmlHTTP.readyState == 4&&xmlHTTP.status==200) {
                    var flag = xmlHTTP.responseText;
                    if (flag == "true") {
                        msg.innerText = "用户名已被占用";
                        msg.style.color = "red";
                    }
                    else {
                        msg.innerText = "用户名可以注册";
                        msg.style.color = "green";
                    }
                }
            }
    }
//验证两次输入的密码是否一致
    function checkPassword()
    {
        var msg=document.getElementById("passwordMsg");
        var password=document.getElementById("password").value;
        var repassword=document.getElementById("repassword").value;
        if(password===repassword)
        {
            msg.innerText = "两次输入的密码一致";
            msg.style.color = "green";
        }
        else
        {
            msg.innerText = "两次输入的密码不一致";
            msg.style.color = "red";
        }
    }

//验证邮箱
    function checkEmail() {
        var reg = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
        var email=document.getElementById("email").value;
        var msg=document.getElementById("emailMsg");
        var f = reg.test(email);
        // alert(f);
        if (f == false) {
            msg.innerText = "邮箱格式不对";
            msg.style.color = "red";
        }
        else
        {
            msg.innerText = "邮箱可使用";
            msg.style.color = "green";
        }

    }

//验证手机号
    function checkPhone() {
        var reg = /1[3578][0-9]{9}/;
        var phone=document.getElementById("phone").value;
        var msg=document.getElementById("telphone");
        var f = reg.test(phone);
        // alert(f);
        if (f == false) {
            msg.innerText = "手机号格式不对";
            msg.style.color = "red";
        }
        else
		{
            msg.innerText = "手机号可使用";
            msg.style.color = "green";
		}

    }


	// 创建XMLHttpRequest对象
	function createXMLHttpRequest() {
        try {
            return new XMLHttpRequest();
        } catch (e) {
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    alert("你用什么浏览器呢？");
                    throw e;
                }
            }
        }
	};
	//切换验证码
	// function changecode(){
	// 	var img = document.getElementById("validateimage");
	// 	img.src = "${pageContext.request.contextPath}/codeaction?a="+new Date().getTime();
	// }
	
	
	
	
	
	
	
	